/********************************************

@Author :yinjinlin<yinjinlin_uplook@163.com>
@Time : 2020/12/28 16:25
@Description:

*********************************************/
package main

import (
	"context"
	"encoding/json"
	"git.900sui.cn/kc/base/utils"
	"git.900sui.cn/kc/kcgin"
	"git.900sui.cn/kc/kcgin/logs"
	"git.900sui.cn/kc/rabbitmq"
	"git.900sui.cn/kc/rpcinterface/client/financial"
	financial2 "git.900sui.cn/kc/rpcinterface/interface/financial"
	"git.900sui.cn/kc/rpcinterface/interface/task/insurance"
	"github.com/streadway/amqp"
)

func main() {
	// consumer client
	rpcFinancial := new(financial.Insurance).Init()
	defer rpcFinancial.Close()

	logs.Info("Environment Variable:MSF_ENV:", kcgin.KcConfig.RunMode)
	new(utils.KcLog).GetInstance(kcgin.AppConfig.String("insurance.log.addInsAssetsTotal"))
	// 连接交换机
	err := rabbitmq.Rabbitmq.Consume(kcgin.AppConfig.String("insurance.queue.addInsAssetsTotal"), func(msg amqp.Delivery) {
		//  rpcTask interface  队列任务的入口 producer
		var res insurance.ArgsCardPackPolicySuc
		if err := json.Unmarshal(msg.Body, &res); err != nil {
			return
		}
		var reply bool
		err := rpcFinancial.AddInsAssetsTotal(context.Background(), &financial2.ArgsInsAssetsTotal{
			TransNo: res.TransNo,
		}, &reply)
		if err != nil {
			utils.Logerr.Printf("保险公司累计保费金额任务失败 保单流水号 TranNo: %s error : %s\n", res.TransNo, err)
		}
	})

	if err != nil {
		utils.Logerr.Printf("保险公司累计保费金额任务失败 err: %s", err.Error())
	}

}
